<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function secretKeySalt() {
	return 'J3t92YHE7kqLCx37cCX0iwnIBinbXXRw9Qb6sSZAVF5BL6IE7VJpUPXbszZcdCe';
}

function computeHash($once) {
    $salt = secretKeySalt();
    return base64_encode(hash_hmac('sha1', $once, $salt, true));
}

$once = get_input('once');
$digest = get_input('digest');
//$t = computeHash($once);
//echo "$once $digest $t<br>";
//die();
if($digest == computeHash($once)) {
    
} else {
   $status = 'ERROR';
    $message = 'Some unexpected error happened! Cannot verify request!';
    $status = urlencode($status);
    $message = urlencode($message);
    forward("web/confirmation/index.php?status=$status&message=$message");
    die();
}

$email = get_input('email');
$users = get_user_by_email($email);
$user = $users[0];
//var_dump($user);
$userid = $user->guid;

if(!$userid) {
    //die(json_encode(export_result(400, 'This email doesn\'t exist')));
    $status = 'ERROR';
    $message = "This email doesn't exist";
    $status = urlencode($status);
    $message = urlencode($message);
    forward("web/confirmation/index.php?status=$status&message=$message");
} else {
    greengar_reset_password($userid);
    //$result = export_result(200, 'Please check email for further instruction');
    //echo json_encode($result);
    $status = 'Thank you!';
    $message = "Please check email for further instruction to reset your password!";
    $status = urlencode($status);
    $message = urlencode($message);
    forward("web/confirmation/index.php?status=$status&message=$message");
}
?>
